/**
 * 个人中心
 * @constructor
 */
function SysConfig() {
}

SysConfig.init = function () {

}
//操作相关方法****************************
function log() {
    if(!validateForm()) return false;
    var postdata={
        userPhone: $("#text_phone").val(),
        userPassword: $("#text_oldpwd").val(),
        userNewPassword: $("#text_newpwd").val(),
    };
    $.ajax({
        url:"/sysConfig/update",
        type:"post",
        data:JSON.stringify(postdata),
        contentType:"application/json",
        dataType:"json",
        success:function(data){
            if (data.code === "200") {
                swal("修改成功!", "请继续操作", "success");
            } else if(data.code==="500"){
                swal("修改失败!", "原密码错误，请重试", "error");
            }else{
                swal("修改失败!", "请重试", "error");
            }
        }
    })
}
jQuery.validator.addMethod("isPhone", function(value, element) {
    var phone = value;
    if(phone!=''){
        var reg01 = /^(0|86|17951)?(13[0-9]|15[012356789]|17[01678]|18[0-9]|14[57])[0-9]{8}$/;
        var reg02 = /^(0[0-9]{2,3}\-)([2-9][0-9]{6,7})+(\-[0-9]{1,4})?$/;
        if(!reg01.test(phone) && !reg02.test(phone)){
            return false
        }
    }
    return true;
}, "(请输入正确的联系方式)");

function validateForm() {
    //validate方法参数可选
    return $("#myformdata").validate({
        rules: {
            text_phone: {
                required: true,//必填
                minlength: 1, //最少1个字符
                isPhone:true,
            },
        },
        //错误信息提示
        messages: {
            text_phone: {
                required: "(必填)",
                minlength: "最少1位",
                isPhone:"(请输入正确的联系方式)"
            },
        },
    }).form();
}
